<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>后台主界面</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/admin.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/daily_record.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/treeview.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/news_list.css' type="text/css" />
<link rel="stylesheet" href='<?php echo $static_url; ?>common/css/news_add.css' type="text/css" />
<script src="<?php echo $static_url; ?>common/js/jquery-1.8.3.min.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>common/js/common.js" type="text/javascript"></script>
<script src="<?php echo $static_url; ?>common/js/jquery.treeview.js" type="text/javascript"></script>
</head>
<body class="body_background">
	<div>
		<?php echo $header_nav; ?>
		<div class="common_container clearfix">
			<div class="crumbs">
				<span class="catalogue">文章管理</span>
				<a href="/www/admin/news/news_lists.php">文章列表</a> |
				<a href="/www/admin/news/news_add.php?category_id=<?php echo $category_id; ?>">添加文章</a> |
				<a href="/www/admin/news/empty_add.php?category_id=<?php echo $category_id; ?>">添加空白文章</a> |
				<a href="/www/admin/news/news_relative.php">手动推荐</a> |
				<a href="/www/admin/news/news_recover.php">回收站</a>
			</div>
			<div class="treeview_container" id="side_container">
				<div class="closeSidebar"><i title="点击隐藏左菜单" class="icon_close"></i></div>
				<h4>文章栏目</h4>
				<ul id="browser" class="filetree"></ul>
			</div>
			<div class="sidebar_container_hidden" style="margin-top:10px;margin-right:5px;"  >
				<div class="openSidebar"><i title="点击显示左菜单" class="icon_open"></i></div>
			</div>
			<div class="daily_record_main">
				<div class="main_container" id="main_container">
					<div>
						<table class="record_tips"><tr><td class="colorstyle">手动推荐</td></tr></table>
						<div class="" id="page-stats">
							<div class="well" style="overflow:auto;margin:10px;">
								<div style="height:30px;line-height:30px;margin:5px 0px;">
									<font color="red">备注：</font>文章站内容页相关文章调用最新四条，论坛帖子的今日推荐小模块调用最新九条。
								</div>
								<table width="100%" class="news_relative_table">
									<thead>
										<tr>
											<th width="10%">排序</th>
											<th width="40%">标题</th>
											<th width="40%">URL地址</th>
											<th width="10%">管理</th>
										</tr>
									</thead>
									<tbody>
									<form action="/www/admin/news/do/do_edit_relative.php" method="post" style="margin:0;" onsubmit="return before_edit_all();">
									<?php foreach($news_relative as $row): ?>
										<tr>
											<td>
												<input name="orders[]" id="orders_<?php echo $row['id']; ?>" class="ipt_style" type="text" value="<?php echo $row['orders']; ?>" style="width:90%">
											</td>
											<td>
												<input name="id[]" type="hidden" value="<?php echo $row['id']; ?>">
												<input name="title[]" id="title_<?php echo $row['id']; ?>" type="text" value="<?php echo $row['title']; ?>"  class="ipt_style" style="width:90%">
											</td>
											<td>
												<input name="url[]" id="url_<?php echo $row['id']; ?>" type="text" value="<?php echo $row['url']; ?>" class="ipt_style" style="width:90%">
											</td>
											<td>
												<a class="btn btn_style" href="javascript:;" onclick="edit_one(<?php echo $row['id']; ?>)" >修改</a>
												<a class="btn btn_style" href="javascript:del(<?php echo $row['id']; ?>);" onclick="return confirm('确定要删除《<?php echo $row['title']; ?>》这个推荐文章吗？')">删除</a>
												<br />
												<span style="color:red" id="point_text_<?php echo $row['id']; ?>">
												</span>
											</td>
										</tr>
									<?php
									endforeach;
									if( empty($news_relative) ){
									?>
										<tr><td colspan="4" style="text-align:left;">暂无推荐文章！</td></tr>
									<?php
									}else{
									?>
										<tr>
											<td colspan="3"> &nbsp; </td>
											<td>
												<input class="btn btn_style" name="submit" type="submit" value="整页修改">
												<br>
												<span style="color:red" id="point_text_all"></span>
											</td>
										</tr>
									<?php
									}
									?>
									</form>
										<tr>
											<td colspan="4" style="text-align:left;">新增推荐文章：</td>
										</tr>
									<form action="/www/admin/news/do/do_add_relative.php" method="post" onsubmit="return add_relative();">
										<tr>
											<td>
												<input name="orders" type="text" value="" class="ipt_style" style="width:90%">
											</td>
											<td>
												<input name="title" id="title" type="text" class="ipt_style" style="width:90%">
											</td>
											<td>
												<input name="url" id="url" type="text" class="ipt_style" style="width:90%">
											</td>
											<td>
												<input class="btn btn_style" name="submit" type="submit" value="添加"><br />
												<span id="add_point_text" style="color:red"></span>
											</td>
										</tr>
									</form>
									<?php if( $page_html != '' ): ?>
										<tr>
											<td class="navPage" colspan="4">&nbsp;&nbsp;<?php echo $page_html; ?></td>
										</tr>
									<?php endif; ?>
									</tbody>
								</table>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
<script>
//加载栏目数据，并实例化
$(function(){
	var browser = $('#browser');
	browser.html('');
	$.ajax({
		type: "POST",
		url: "/admin/news/ajax/ajax_news_left_baner.php",
		dataType: 'html',
		data: {},
		beforeSend: function(){
			browser.html( '加载中...' );
		},
		success: function(data){
			browser.html( data ).treeview();
		}
	});
});

//添加前检查
function add_relative(){
	var add_point_text = $('#add_point_text');
	var url = $('#url').val();
	if( $('#title').val() == '' ){
		add_point_text.html('请输入标题');
		$('#title').focus();
	}else if( url == '' ){
		add_point_text.html('请输入URL链接');
		$('#url').focus();
	}else if( url.length < 7 || url.length > 255 || url.substr(0, 4) != 'http' ){
		add_point_text.html('请输入正确URL');
		$('#url').focus();
	}else{
		return true;
	}
	return false;
}

//删除
function del(i){<!-- i:id号 -->
	$.ajax({
		type: "POST",
		url: "/admin/news/ajax/ajax_del_relative.php",
		dataType: 'json',
		data: {"id":i},
		beforeSend: function(){
			$('#point_text_'+i).html('处理中...');
		},
		success: function(msg){
			alert(msg.string);
			window.top.location.reload();
		}
	});
}

//修改单个
function edit_one(id){
	var orders = $('#orders_'+id).val();
	var title = $('#title_'+id).val();
	var url = $('#url_'+id).val();
	var point_text = $('#point_text_'+id);
	$.ajax({
		type: "POST",
		url: "/admin/news/ajax/ajax_edit_relative.php?id="+id,
		dataType:'json',
		data: {"orders":orders,"title":title,"url":url},
		beforeSend: function(){
			point_text.html('处理中...');
		},
		success: function(msg){
			if( msg.error == false ){
				point_text.html('参数有误');
			}else{
				point_text.html('修改成功');
			}
			setTimeout(function(){point_text.html('');}, 2000);
		}
	});
}

//整页修改提交之前
function before_edit_all(){
	$('#point_text_all').html('处理中...');
	return true;
}
</script>
</body>
</html>